
##########################
### MEDIATION ANALYSIS ###
##########################

library(mediation)

options(scipen=999)

### PCA 

PCA_bivariate <- lm(PCA_activism ~ Gender,
                    data = PRRdataframe2, weights = df_weights)
modelsummary(PCA_bivariate, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

PCA_fullmodel <- lm(PCA_activism ~ Gender + Policyinfluence + Ambitioncand +
                      Partyrecruitment + Newfriends + Stigma +
                      age + agesquared + Tertiaryedu + Labourforce + yearsmember + Party,
                    data = PRRdataframe2, weights = df_weights)
modelsummary(PCA_fullmodel, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames,
             output = "PCA full model.docx")

#==================================================================#

# Pol efficacy

meeting_0_efficacy <- lm(PCA_activism ~ Gender + Tertiaryedu + Labourforce +
                           Ambitioncand + Partyrecruitment + Newfriends + Stigma +
                           age + agesquared + yearsmember + Party,
                         data = PRRdataframe2, weights = df_weights)
modelsummary(meeting_0_efficacy, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

meeting_M_efficacy <- glm(Policyinfluence ~ Gender + Tertiaryedu + Labourforce +
                            Ambitioncand + Partyrecruitment + Newfriends + Stigma +
                            age + agesquared + yearsmember + Party,
                          data = PRRdataframe2, weights = df_weights, family = "binomial")
modelsummary(meeting_M_efficacy, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames) # No relationship
PseudoR2(meeting_M_efficacy)

# Ambition

meeting_0_ambition <- lm(PCA_activism ~ Gender + Tertiaryedu + Labourforce +
                           Policyinfluence + Partyrecruitment + Newfriends + Stigma +
                           age + agesquared + yearsmember + Party,
                         data = PRRdataframe2, weights = df_weights)
modelsummary(meeting_0_ambition, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

meeting_M_ambition <- glm(Ambitioncand ~ Gender + Tertiaryedu + Labourforce +
                            Policyinfluence + Partyrecruitment + Newfriends + Stigma +
                            age + agesquared + yearsmember + Party,
                          data = PRRdataframe2, weights = df_weights, family = "binomial")
modelsummary(meeting_M_ambition, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)
PseudoR2(meeting_M_ambition)

meeting_Y_ambition <- lm(PCA_activism ~ Gender + Ambitioncand + Tertiaryedu + Labourforce +
                           Policyinfluence + Partyrecruitment + Newfriends + Stigma +
                           age + agesquared + yearsmember + Party,
                         data = PRRdataframe2, weights = df_weights)
modelsummary(meeting_Y_ambition, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)


motiv_med_table <- list(meeting_0_efficacy, meeting_M_efficacy,
                        meeting_0_ambition, meeting_M_ambition)

modelsummary(motiv_med_table, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames,
             output = "Mediation - Motivations.docx")

#==================================================================#

# Stigma

meeting_0_stigma <- lm(PCA_activism ~ Gender + Tertiaryedu + Labourforce +
                         Policyinfluence + Ambitioncand + Partyrecruitment + Newfriends +
                         age + agesquared + yearsmember + Party,
                       data = PRRdataframe2, weights = df_weights)
modelsummary(meeting_0_stigma, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

meeting_M_stigma <- glm(Stigma ~ Gender + Tertiaryedu + Labourforce +
                          Policyinfluence + Ambitioncand + Partyrecruitment + Newfriends +
                          age + agesquared + yearsmember + Party,
                        data = PRRdataframe2, weights = df_weights, family = "binomial")
modelsummary(meeting_M_stigma, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames) # No relationship
PseudoR2(meeting_M_stigma)

stigma_med_table <- list(meeting_0_stigma, meeting_M_stigma)


modelsummary(stigma_med_table, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames,
             output = "Mediation - Stigma.docx")

#==================================================================#

# Recruitment

meeting_0_recruit <- lm(PCA_activism ~ Gender + Tertiaryedu + Labourforce +
                          Policyinfluence + Ambitioncand + Newfriends + Stigma +
                          age + agesquared + yearsmember + Party,
                        data = PRRdataframe2, weights = df_weights)
modelsummary(meeting_0_recruit, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

meeting_M_recruit <- glm(Partyrecruitment ~ Gender + Tertiaryedu + Labourforce +
                           Policyinfluence + Ambitioncand + Newfriends + Stigma +
                           age + agesquared + yearsmember + Party,
                         data = PRRdataframe2, weights = df_weights, family = "binomial")
modelsummary(meeting_M_recruit, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)
PseudoR2(meeting_M_recruit)

meeting_Y_recruit <- lm(PCA_activism ~ Gender + Partyrecruitment + Tertiaryedu + Labourforce +
                          Policyinfluence + Ambitioncand + Newfriends + Stigma +
                          age + agesquared + yearsmember + Party,
                        data = PRRdataframe2, weights = df_weights)
modelsummary(meeting_Y_recruit, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

# New friends

meeting_0_friends <- lm(PCA_activism ~ Gender + Tertiaryedu + Labourforce +
                          Policyinfluence + Ambitioncand + Partyrecruitment + Stigma +
                          age + agesquared + yearsmember + Party,
                        data = PRRdataframe2, weights = df_weights)
modelsummary(meeting_0_friends, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

meeting_M_friends <- glm(Newfriends ~ Gender + Tertiaryedu + Labourforce +
                           Policyinfluence + Ambitioncand + Partyrecruitment + Stigma +
                           age + agesquared + yearsmember + Party,
                         data = PRRdataframe2, weights = df_weights, family = "binomial")
modelsummary(meeting_M_friends, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)
PseudoR2(meeting_M_friends)

meeting_Y_friends <- lm(PCA_activism ~ Gender + Newfriends + Tertiaryedu + Labourforce +
                          Policyinfluence + Ambitioncand + Partyrecruitment + Stigma +
                          age + agesquared + yearsmember + Party,
                        data = PRRdataframe2, weights = df_weights)
modelsummary(meeting_Y_friends, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

motiv_networks_table <- list(meeting_0_recruit, meeting_M_recruit,
                        meeting_0_friends, meeting_M_friends)

modelsummary(motiv_networks_table, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames,
             output = "Mediation - Networks.docx")

#==================================================================#

### Bootstrapping

# Recruitment

set.seed(2024)

PCA_recruit_results <- mediate(meeting_M_recruit, meeting_Y_recruit,
                               treat = "Gender", mediator = "Partyrecruitment",
                               sims = 500)

summary(PCA_recruit_results)
plot(PCA_recruit_results, main = "CMA | Gender and party recruitment")

# New friends

set.seed(2024)

PCA_friends_results <- mediate(meeting_M_friends, meeting_Y_friends,
                               treat = "Gender", mediator = "Newfriends",
                               sims = 500)

summary(PCA_friends_results)
plot(PCA_friends_results, main = "CMA | Gender and new friends since joining")


#==================================================================#
#==================================================================#
#==================================================================#


### MEDIATION ANALYSIS FOR DIFFERENT ACTIVITIES ###

### ONLINE ###

# Recruitment

online_0_recruit <- lm(online_num ~ Gender + Tertiaryedu + Labourforce +
                         Policyinfluence + Ambitioncand + Newfriends + Stigma +
                         age + agesquared + yearsmember + Party,
                       data = PRRdataframe2, weights = df_weights)
modelsummary(online_0_recruit, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

online_M_recruit <- glm(Partyrecruitment ~ Gender + Tertiaryedu + Labourforce +
                          Policyinfluence + Ambitioncand + Newfriends + Stigma +
                          age + agesquared + yearsmember + Party,
                        data = PRRdataframe2, weights = df_weights, family = "binomial")
modelsummary(online_M_recruit, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

online_Y_recruit <- lm(online_num ~ Gender + Partyrecruitment + Tertiaryedu + Labourforce +
                         Policyinfluence + Ambitioncand + Newfriends + Stigma +
                         age + agesquared + yearsmember + Party,
                       data = PRRdataframe2, weights = df_weights)
modelsummary(online_Y_recruit, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

# New friends

online_0_friends <- lm(online_num ~ Gender + Tertiaryedu + Labourforce +
                         Policyinfluence + Ambitioncand + Partyrecruitment + Stigma +
                         age + agesquared + yearsmember + Party,
                       data = PRRdataframe2, weights = df_weights)
modelsummary(online_0_friends, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

online_M_friends <- glm(Newfriends ~ Gender + Tertiaryedu + Labourforce +
                          Policyinfluence + Ambitioncand + Partyrecruitment + Stigma +
                          age + agesquared + yearsmember + Party,
                        data = PRRdataframe2, weights = df_weights, family = "binomial")
modelsummary(online_M_friends, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

online_Y_friends <- lm(online_num ~ Gender + Newfriends + Tertiaryedu + Labourforce +
                         Policyinfluence + Ambitioncand + Partyrecruitment + Stigma +
                         age + agesquared + yearsmember + Party,
                       data = PRRdataframe2, weights = df_weights)
modelsummary(online_Y_friends, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

#==================================================================#

### Bootstrapping

# Recruitment

set.seed(2024)

online_recruit_results <- mediate(online_M_recruit, online_Y_recruit,
                                  treat = "Gender", mediator = "Partyrecruitment",
                                  sims = 1000)

summary(online_recruit_results)

# New friends

set.seed(2024)

online_friends_results <- mediate(online_M_friends, online_Y_friends,
                                  treat = "Gender", mediator = "Newfriends",
                                  sims = 1000)

summary(online_friends_results)

#==================================================================#
#==================================================================#

### MEETINGS ###

# Recruitment

meet_0_recruit <- lm(meeting_num ~ Gender + Tertiaryedu + Labourforce +
                       Policyinfluence + Ambitioncand + Newfriends + Stigma +
                       age + agesquared + yearsmember + Party,
                     data = PRRdataframe2, weights = df_weights)
modelsummary(meet_0_recruit, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

meet_M_recruit <- glm(Partyrecruitment ~ Gender + Tertiaryedu + Labourforce +
                        Policyinfluence + Ambitioncand + Newfriends + Stigma +
                        age + agesquared + yearsmember + Party,
                      data = PRRdataframe2, weights = df_weights, family = "binomial")
modelsummary(meet_M_recruit, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

meet_Y_recruit <- lm(meeting_num ~ Gender + Partyrecruitment + Tertiaryedu + Labourforce +
                       Policyinfluence + Ambitioncand + Newfriends + Stigma +
                       age + agesquared + yearsmember + Party,
                     data = PRRdataframe2, weights = df_weights)
modelsummary(meet_Y_recruit, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

# New friends

meet_0_friends <- lm(meeting_num ~ Gender + Tertiaryedu + Labourforce +
                       Policyinfluence + Ambitioncand + Partyrecruitment + Stigma +
                       age + agesquared + yearsmember + Party,
                     data = PRRdataframe2, weights = df_weights)
modelsummary(meet_0_friends, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

meet_M_friends <- glm(Newfriends ~ Gender + Tertiaryedu + Labourforce +
                        Policyinfluence + Ambitioncand + Partyrecruitment + Stigma +
                        age + agesquared + yearsmember + Party,
                      data = PRRdataframe2, weights = df_weights, family = "binomial")
modelsummary(meet_M_friends, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

meet_Y_friends <- lm(meeting_num ~ Gender + Newfriends + Tertiaryedu + Labourforce +
                       Policyinfluence + Ambitioncand + Partyrecruitment + Stigma +
                       age + agesquared + yearsmember + Party,
                     data = PRRdataframe2, weights = df_weights)
modelsummary(meet_Y_friends, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

### Bootstrapping

# Recruitment

set.seed(2024)

meet_recruit_results <- mediate(meet_M_recruit, meet_Y_recruit,
                                treat = "Gender", mediator = "Partyrecruitment",
                                sims = 1000)

summary(meet_recruit_results)

# New friends

set.seed(2024)

meet_friends_results <- mediate(meet_M_friends, meet_Y_friends,
                                treat = "Gender", mediator = "Newfriends",
                                sims = 1000)

summary(meet_friends_results)

#==================================================================#
#==================================================================#

### FLYERS ###

# Recruitment

flyers_0_recruit <- lm(flyers_num ~ Gender + Tertiaryedu + Labourforce +
                         Policyinfluence + Ambitioncand + Newfriends + Stigma +
                         age + agesquared + yearsmember + Party,
                       data = PRRdataframe2, weights = df_weights)
modelsummary(flyers_0_recruit, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

flyers_M_recruit <- glm(Partyrecruitment ~ Gender + Tertiaryedu + Labourforce +
                          Policyinfluence + Ambitioncand + Newfriends + Stigma +
                          age + agesquared + yearsmember + Party,
                        data = PRRdataframe2, weights = df_weights, family = "binomial")
modelsummary(flyers_M_recruit, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

flyers_Y_recruit <- lm(flyers_num ~ Gender + Partyrecruitment + Tertiaryedu + Labourforce +
                         Policyinfluence + Ambitioncand + Newfriends + Stigma +
                         age + agesquared + yearsmember + Party,
                       data = PRRdataframe2, weights = df_weights)
modelsummary(flyers_Y_recruit, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

# New friends

flyers_0_friends <- lm(flyers_num ~ Gender + Tertiaryedu + Labourforce +
                         Policyinfluence + Ambitioncand + Partyrecruitment + Stigma +
                         age + agesquared + yearsmember + Party,
                       data = PRRdataframe2, weights = df_weights)
modelsummary(flyers_0_friends, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

flyers_M_friends <- glm(Newfriends ~ Gender + Tertiaryedu + Labourforce +
                          Policyinfluence + Ambitioncand + Partyrecruitment + Stigma +
                          age + agesquared + yearsmember + Party,
                        data = PRRdataframe2, weights = df_weights, family = "binomial")
modelsummary(flyers_M_friends, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

flyers_Y_friends <- lm(flyers_num ~ Gender + Newfriends + Tertiaryedu + Labourforce +
                         Policyinfluence + Ambitioncand + Partyrecruitment + Stigma +
                         age + agesquared + yearsmember + Party,
                       data = PRRdataframe2, weights = df_weights)
modelsummary(flyers_Y_friends, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

### Bootstrapping

# Recruitment

set.seed(2024)

flyers_recruit_results <- mediate(flyers_M_recruit, flyers_Y_recruit,
                                  treat = "Gender", mediator = "Partyrecruitment",
                                  sims = 1000)

summary(flyers_recruit_results)

# New friends

set.seed(2024)

flyers_friends_results <- mediate(flyers_M_friends, flyers_Y_friends,
                                  treat = "Gender", mediator = "Newfriends",
                                  sims = 1000)

summary(flyers_friends_results)


#==================================================================#
#==================================================================#
#==================================================================#


### RC: MEDIATION ANALYSIS FOR LEAGUE AND SD ###

### LEAGUE ###

PCA_fullmodel_L <- lm(PCA_activism ~ Gender + Tertiaryedu + Labourforce +
                      Policyinfluence + Ambitioncand + Partyrecruitment + Newfriends + Stigma +
                      age + agesquared + yearsmember,
                    data = Leaguedataframe)
modelsummary(PCA_fullmodel_L, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)

# Pol efficacy

meeting_0_efficacy <- lm(PCA_activism ~ Gender + Tertiaryedu + Labourforce +
                           Ambitioncand + Partyrecruitment + Newfriends + Stigma +
                           age + agesquared + yearsmember,
                         data = Leaguedataframe)
modelsummary(meeting_0_efficacy, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)

meeting_M_efficacy <- glm(Policyinfluence ~ Gender + Tertiaryedu + Labourforce +
                            Ambitioncand + Partyrecruitment + Newfriends + Stigma +
                            age + agesquared + yearsmember,
                          data = Leaguedataframe, family = "binomial")
modelsummary(meeting_M_efficacy, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames) # No relationship
PseudoR2(meeting_M_efficacy)

# Ambition

meeting_0_ambition <- lm(PCA_activism ~ Gender + Tertiaryedu + Labourforce +
                           Policyinfluence + Partyrecruitment + Newfriends + Stigma +
                           age + agesquared + yearsmember,
                         data = Leaguedataframe)
modelsummary(meeting_0_ambition, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)

meeting_M_ambition <- glm(Ambitioncand ~ Gender + Tertiaryedu + Labourforce +
                            Policyinfluence + Partyrecruitment + Newfriends + Stigma +
                            age + agesquared + yearsmember,
                          data = Leaguedataframe, family = "binomial")
modelsummary(meeting_M_ambition, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)
PseudoR2(meeting_M_ambition)

meeting_Y_ambition <- lm(PCA_activism ~ Gender + Ambitioncand + Tertiaryedu + Labourforce +
                           Policyinfluence + Partyrecruitment + Newfriends + Stigma +
                           age + agesquared + yearsmember,
                         data = Leaguedataframe)
modelsummary(meeting_Y_ambition, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)

# Stigma

meeting_0_stigma <- lm(PCA_activism ~ Gender + Tertiaryedu + Labourforce +
                         Policyinfluence + Ambitioncand + Partyrecruitment + Newfriends +
                         age + agesquared + yearsmember,
                       data = Leaguedataframe)
modelsummary(meeting_0_stigma, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)

meeting_M_stigma <- glm(Stigma ~ Gender + Tertiaryedu + Labourforce +
                          Policyinfluence + Ambitioncand + Partyrecruitment + Newfriends +
                          age + agesquared + yearsmember,
                        data = Leaguedataframe, family = "binomial")
modelsummary(meeting_M_stigma, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)
PseudoR2(meeting_M_stigma)

# Recruitment

meeting_0_recruit <- lm(PCA_activism ~ Gender + Tertiaryedu + Labourforce +
                          Policyinfluence + Ambitioncand + Newfriends + Stigma +
                          age + agesquared + yearsmember,
                        data = Leaguedataframe)
modelsummary(meeting_0_recruit, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)

meeting_M_recruit <- glm(Partyrecruitment ~ Gender + Tertiaryedu + Labourforce +
                           Policyinfluence + Ambitioncand + Newfriends + Stigma +
                           age + agesquared + yearsmember,
                         data = Leaguedataframe, family = "binomial")
modelsummary(meeting_M_recruit, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)
PseudoR2(meeting_M_recruit)

meeting_Y_recruit <- lm(PCA_activism ~ Gender + Partyrecruitment + Tertiaryedu + Labourforce +
                          Policyinfluence + Ambitioncand + Newfriends + Stigma +
                          age + agesquared + yearsmember,
                        data = Leaguedataframe)
modelsummary(meeting_Y_recruit, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)

# New friends

meeting_0_friends <- lm(PCA_activism ~ Gender + Tertiaryedu + Labourforce +
                          Policyinfluence + Ambitioncand + Partyrecruitment + Stigma +
                          age + agesquared + yearsmember,
                        data = Leaguedataframe)
modelsummary(meeting_0_friends, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)

meeting_M_friends <- glm(Newfriends ~ Gender + Tertiaryedu + Labourforce +
                           Policyinfluence + Ambitioncand + Partyrecruitment + Stigma +
                           age + agesquared + yearsmember,
                         data = Leaguedataframe, family = "binomial")
modelsummary(meeting_M_friends, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)
PseudoR2(meeting_M_friends)

#==================================================================#

# Recruitment

set.seed(2024)

PCA_recruit_results_League <- mediate(meeting_M_recruit, meeting_Y_recruit,
                                      treat = "Gender", mediator = "Partyrecruitment",
                                      sims = 500)

summary(PCA_recruit_results_League)
plot(PCA_recruit_results_League)

#==================================================================#
#==================================================================#

### SD ###

PCA_fullmodel_SD <- lm(PCA_activism ~ Gender + Tertiaryedu + Labourforce +
                      Policyinfluence + Ambitioncand + Partyrecruitment + Newfriends + Stigma +
                      age + agesquared + yearsmember,
                    data = SDdataframe)
modelsummary(PCA_fullmodel_SD, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)

# Pol efficacy

meeting_0_efficacy <- lm(PCA_activism ~ Gender + Tertiaryedu + Labourforce +
                           Ambitioncand + Partyrecruitment + Newfriends + Stigma +
                           age + agesquared + yearsmember,
                         data = SDdataframe)
modelsummary(meeting_0_efficacy, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)

meeting_M_efficacy <- glm(Policyinfluence ~ Gender + Tertiaryedu + Labourforce +
                            Ambitioncand + Partyrecruitment + Newfriends + Stigma +
                            age + agesquared + yearsmember,
                          data = SDdataframe, family = "binomial")
modelsummary(meeting_M_efficacy, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)
PseudoR2(meeting_M_efficacy)

# Ambition

meeting_0_ambition <- lm(PCA_activism ~ Gender + Tertiaryedu + Labourforce +
                           Policyinfluence + Partyrecruitment + Newfriends + Stigma +
                           age + agesquared + yearsmember,
                         data = SDdataframe)
modelsummary(meeting_0_ambition, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)

meeting_M_ambition <- glm(Ambitioncand ~ Gender + Tertiaryedu + Labourforce +
                            Policyinfluence + Partyrecruitment + Newfriends + Stigma +
                            age + agesquared + yearsmember,
                          data = SDdataframe, family = "binomial")
modelsummary(meeting_M_ambition, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)
PseudoR2(meeting_M_ambition)

meeting_Y_ambition <- lm(PCA_activism ~ Gender + Ambitioncand + Tertiaryedu + Labourforce +
                           Policyinfluence + Partyrecruitment + Newfriends + Stigma +
                           age + agesquared + yearsmember,
                         data = SDdataframe)
modelsummary(meeting_Y_ambition, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)

# Stigma

meeting_0_stigma <- lm(PCA_activism ~ Gender + Tertiaryedu + Labourforce +
                         Policyinfluence + Ambitioncand + Partyrecruitment + Newfriends +
                         age + agesquared + yearsmember,
                       data = SDdataframe)
modelsummary(meeting_0_stigma, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)

meeting_M_stigma <- glm(Stigma ~ Gender + Tertiaryedu + Labourforce +
                          Policyinfluence + Ambitioncand + Partyrecruitment + Newfriends +
                          age + agesquared + yearsmember,
                        data = SDdataframe, family = "binomial")
modelsummary(meeting_M_stigma, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)
PseudoR2(meeting_M_stigma)

meeting_Y_stigma <- lm(PCA_activism ~ Gender + Tertiaryedu + Labourforce +
                         Policyinfluence + Ambitioncand + Partyrecruitment + Newfriends + Stigma +
                         age + agesquared + yearsmember,
                       data = SDdataframe)
modelsummary(meeting_Y_stigma, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)

# Recruitment

meeting_0_recruit <- lm(PCA_activism ~ Gender + Tertiaryedu + Labourforce +
                          Policyinfluence + Ambitioncand + Newfriends + Stigma +
                          age + agesquared + yearsmember,
                        data = SDdataframe)
modelsummary(meeting_0_recruit, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)

meeting_M_recruit <- glm(Partyrecruitment ~ Gender + Tertiaryedu + Labourforce +
                           Policyinfluence + Ambitioncand + Newfriends + Stigma +
                           age + agesquared + yearsmember,
                         data = SDdataframe, family = "binomial")
modelsummary(meeting_M_recruit, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)
PseudoR2(meeting_M_recruit)

meeting_Y_recruit <- lm(PCA_activism ~ Gender + Partyrecruitment + Tertiaryedu + Labourforce +
                          Policyinfluence + Ambitioncand + Newfriends + Stigma +
                          age + agesquared + yearsmember,
                        data = SDdataframe)
modelsummary(meeting_Y_recruit, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)

# New friends

meeting_0_friends <- lm(PCA_activism ~ Gender + Tertiaryedu + Labourforce +
                          Policyinfluence + Ambitioncand + Partyrecruitment + Stigma +
                          age + agesquared + yearsmember,
                        data = SDdataframe)
modelsummary(meeting_0_friends, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)

meeting_M_friends <- glm(Newfriends ~ Gender + Tertiaryedu + Labourforce +
                           Policyinfluence + Ambitioncand + Partyrecruitment + Stigma +
                           age + agesquared + yearsmember,
                         data = SDdataframe, family = "binomial")
modelsummary(meeting_M_friends, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)
PseudoR2(meeting_M_friends)

meeting_Y_friends <- lm(PCA_activism ~ Gender + Tertiaryedu + Labourforce +
                          Policyinfluence + Ambitioncand + Partyrecruitment + Newfriends + Stigma +
                          age + agesquared + yearsmember,
                        data = SDdataframe)
modelsummary(meeting_Y_friends, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames)

#==================================================================#

# Recruitment

set.seed(2024)

PCA_recruit_results_SD <- mediate(meeting_M_recruit, meeting_Y_recruit,
                                  treat = "Gender", mediator = "Partyrecruitment",
                                  sims = 500)

summary(PCA_recruit_results_SD)
plot(PCA_recruit_results_SD)

# New friends

set.seed(2024)

PCA_friends_results_SD <- mediate(meeting_M_friends, meeting_Y_friends,
                                  treat = "Gender", mediator = "Newfriends",
                                  sims = 500)

summary(PCA_friends_results_SD)
plot(PCA_friends_results_SD)

#==================================================================#

PCA_models <- list(PCA_fullmodel_L, PCA_fullmodel_SD)

modelsummary(PCA_models, stars = TRUE, vcov = ~county, coef_rename = coefficientsnames,
             output = "PCA League $ SD")


